package com.yanqu.road.server.cmd.activity;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.LiveShowProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.DailyDataModule;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_LIVE_SHOW_NOTIFY, desc = "直播通知")
public class LiveShowNotifyCmd extends AbstractCommand {
	private int type;
	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		LiveShowProto.LiveShowNotifyReqMsg reqMsg = LiveShowProto.LiveShowNotifyReqMsg.parseFrom(packet.getBytes());
		type = reqMsg.getType();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		if(1 == type){//开播
			player.setLiveShow();
		}else if(2 == type){//关播
			if(player.isLiveShow()){//开播状态
				player.getModule(DailyDataModule.class).calcLiveShowTime(false,true);
			}
		}else {
			ret = GameErrorCode.E_GAME_ERROR;
		}
	}

	@Override
	public void sendData(GamePlayer player) {
		LiveShowProto.LiveShowNotifyRespMsg.Builder respMsg = LiveShowProto.LiveShowNotifyRespMsg.newBuilder();
		respMsg.setRet(ret);
		player.sendPacket(Protocol.U_LIVE_SHOW_NOTIFY, respMsg);
	}

}
